package cn.edu.gdu.quizpractice.service.impl;

import cn.edu.gdu.quizpractice.dao.ManagerDao;
import cn.edu.gdu.quizpractice.entity.Manager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class ManagerUserDetails implements UserDetailsService {

    @Autowired
    private ManagerDao managerDao;

    @Override
    public UserDetails loadUserByUsername(String telephone) throws UsernameNotFoundException {
        Manager manager = managerDao.findByTele(telephone)
                .orElseThrow(() -> new UsernameNotFoundException("管理员不存在"));
        return manager;
    }
} 